package com.note.simpleshop.module.user.dao;

import com.note.simpleshop.entity.TbAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface AddressRepository extends JpaRepository<TbAddress, String> {
    /***
     * 查询用户地址
     * @param userId
     * @param isDelete
     * @return
     */
    List<TbAddress> findByUserIdAndIsDelete(String userId, Integer isDelete);
    TbAddress findByIdAndUserIdAndIsDelete(String id,String userId,Integer isDelete);

    @Transactional()
    @Modifying
    @Query("update TbAddress  set isUse = ?1 where userId=?2")
    void updateIsUse(Integer isUse,String userId);
    @Transactional()
    @Modifying
    @Query("update TbAddress  set isDelete = ?1 where id=?2")
    void updateIsDelete(Integer isDelete,String id);
}